package com.buba.record.controller;


import com.buba.utils.R;
import com.buba.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 体检报告表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-06-09
 */
@RestController
@RequestMapping("/record/physical-report")
public class PhysicalReportController {

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("/generateSerialNo")
    public R generateSerialNo(){
        //定义需要返回的流水号
        String serialNo = null;
        //先查询到今天的日期，格式:"yyyyMMdd"
        String todayDate = new SimpleDateFormat("yyyyMMdd")
                .format(new Date());
        String LSH = "LSH";
        Object lsh = redisUtil.get("LSH");
        if (lsh != null){
            lsh = redisUtil.incr("LSH" , 1);
        }else{
            redisUtil.set("LSH" , todayDate+"0001");
            lsh = redisUtil.get("LSH");
        }

        serialNo = LSH+lsh;
        return R.ok().data("LSH" , serialNo);
    }



}

